package com.tmc.dao.impl.intair;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.tmc.bean.common.ContextInfo;
import com.tmc.dao.impl.BaseDaoImpl;
import com.tmc.entity.intair.IntairSegment;
import com.tmc.util.ObjectUtil;

@Repository
public class IntairSegmentDaoImpl extends BaseDaoImpl<IntairSegment> {

	public List<IntairSegment> findByFlightId(ContextInfo context, Long flightId) {
		if (flightId == null) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from IntairSegment c where c.enabledFlag = 'Y' ");
		sql.append(" and c.flightId = :flightId ");
		params.put("flightId", flightId);
		return this.findList(sql.toString(), params);
	}
	public List<IntairSegment> findByFlightIdAndFlightNo(ContextInfo context, Long flightId ,String flightNo) {
		if (flightId == null) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from IntairSegment c where c.enabledFlag = 'Y' ");
		sql.append(" and c.flightId = :flightId ");
		params.put("flightId", flightId);
		
		if(ObjectUtil.hasText(flightNo)){
			sql.append(" and c.flightNo = :flightNo ");
			params.put("flightNo", flightNo);		
		}
		
		return this.findList(sql.toString(), params);
	}

}
